package com.mf.security.handler;


import io.github.heollhai.common.result.Result;
import io.github.heollhai.common.result.ResultCodeEnum;
import io.github.heollhai.common.utils.ResponseUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: lmf
 * @Create: 2024/8/6 14:32
 * Description: 登录认证过程异常处理
 */
@Component
public class LoginAuthenticationFailureHandlerImpl implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        Result<String> result = Result.fail(ResultCodeEnum.AUTHENTICATION_FAILED);
        ResponseUtils.writeJson(response, result);
    }
}